from socket import *
#发送数据
# udp_socket = socket(AF_INET,SOCK_DGRAM)
# send_data = 'i love you'
# udp_addr_port = ('192.168.56.1',8080)
# udp_socket.sendto(send_data.encode('utf-8'),udp_addr_port)
# # udp_socket.sendto(send_data.encode('gbk'),udp_addr_port)
# udp_socket.close()
#接收数据
# udp_socket = socket(AF_INET,SOCK_DGRAM)
# send_data = '你那边天气怎么样? '.encode('utf-8')
# udp_addr_port = ('192.168.56.1',8080)
# udp_socket.sendto(send_data,udp_addr_port)
# #本次接收的最大字节数
# recv_data = udp_socket.recvfrom(1024)
# # print(recv_data)
# print(recv_data[0].decode('utf-8'))
# # print(recv_data[1])
# udp_socket.close()
#绑定端口通讯
while True:
    udp_socket = socket(AF_INET, SOCK_DGRAM)
    # IP地址一般不用写, 表示本机的任何一个IP
    udp_socket.bind(('', 9999))
    send_data = '你那边天气怎么样? '.encode('utf-8')
    udp_addr_port = ('192.168.56.1', 8087)
    udp_socket.sendto(send_data, udp_addr_port)
    recv_data = udp_socket.recvfrom(1024)
    print(recv_data[0].decode('utf-8'))
    udp_socket.close()